package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.NeedsEntity;
import com.sgb.kjwl.view.ui.activity.demand.DemandDetailsActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class MaterialSellerAdapter extends BaseRecycleAdapter<NeedsEntity> {

    private TextView tv_look;
    private TextView tv_no;
    private TextView tv_time;
    private MaterialSellerChildAdapter childAdapter;
    private RecyclerView recyclerView;
    private LinearLayoutManager linearLayoutManager;
    private int type;

    public MaterialSellerAdapter(Context context, List<NeedsEntity> datas,int type) {
        super(context, R.layout.item_seller, datas);
        this.type = type;
    }

    @Override
    public void convert(ItemViewHolder holder, final NeedsEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        recyclerView = holder.itemView.findViewById(R.id.rv);
        tv_no = holder.itemView.findViewById(R.id.tv_no);
        tv_time = holder.itemView.findViewById(R.id.tv_time);
        tv_no.setText("需求编号：" + entity.getNo());
        tv_time.setText("发布时间：" + entity.getPublishTime());
        tv_look = holder.itemView.findViewById(R.id.tv_look);

        tv_look.setOnClickListener(view -> {
            DemandDetailsActivity.start(context,entity.getNo(),type);
        });
        linearLayoutManager = new LinearLayoutManager(context);
        childAdapter = new MaterialSellerChildAdapter(context, entity.getGoodsList());
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(childAdapter);
    }
}
